package xiangmu;

public class GongSi {
    private String name;
    private String adress;
    private Car[] car = new Car[100];
    private  Kehuxinxi []kehu=new Kehuxinxi[100];
    private int sum=0;
    private int count = 0;
    public GongSi(){
        car[count]=new JiaoChe("皖A666","特斯拉",300,"model3");
        count++;
        car[count]=new KeChe("皖A677","金龙",300,30);
        count++;
    }

    public GongSi(String name, String adress) {
       // this();
        this.name = name;
        this.adress = adress;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    public void show() {
        System.out.println("公司在" + getAdress() + ",欢迎来租车，也可以致电9999999洽谈相关业务");
    }
    //1.查看车辆情况 实际上就是遍历数组
    public void chakan() {
        if (count == 0) {
            System.out.println("抱歉，公司现在无车可租");
            return;
        }
        for (int i = 0; i < count; i++) {
                car[i].show();
                System.out.println();
            }

        }
//租车显示内容2
    public void xianshi(String xianshi) {
        if (count == 0) {
            System.out.println("抱歉，公司现在无车可租");
            return;
        }
        for (int i = 0; i < count; i++) {
            if(car[i].getChuzuzhuangtai()!=1)
                continue;
            if (car[i] instanceof JiaoChe&&xianshi.equals("轿车")) {
                car[i].show();
            }else if(car[i] instanceof KeChe&&xianshi.equals("客车")){
                car[i].show();
            }
        }
    }
//租车
    public Car zu( String chepai) {
        if (count == 0) {
            System.out.println("无车可租");
            return null;
        }
        for (int i = 0; i < count; i++) {
            if (car[i].getChepai().equals(chepai)&&car[i].getChuzuzhuangtai()==1) {
                System.out.println("您租的是" + car[i].getPinpai());
                car[i].setChuzuzhuangtai(2);
                return car[i];
            }
        }
        return null;
    }
    public boolean baofei(String chepai){
        for(int i=0;i<count;i++){
            if(chepai.equals(car[i].getChepai())){
                if(car[i].getChuzuzhuangtai()!=2){
                    for(int j=i;j<count-1;j++){
                        car[j]=car[j+1];
                    }
                    car[count-1]=null;
                    count--;
                    return true;
                }else{
                    System.out.println("正在出租呢");
                    return false;
                }
            }

        }
        return false;
    }
    //    5.加入新车
    public void addCar(Car c) {
        if (count >= car.length) {
            System.out.println("公司车位已经满了 加不了新车了");
            return;
        }
        car[count] = c;
        count++;
    }

    public boolean huan(String chepai) {
        for (int i = 0; i < count; i++) {
            if (chepai.equals(car[i].getChepai())&&car[i].getChuzuzhuangtai()==2) {
                car[i].setChuzuzhuangtai(1);
                return true;
            }
        }
        return false;
    }
    public void addKehu(Kehuxinxi C){
        if(sum>=kehu.length){
            System.out.println("记录已经满了");
        }
        kehu[sum]=C;
        sum++;
    }
    public void showkehuxinxi(){
        if(sum==0)
            System.out.println("暂无租车记录");
        for(int i=0;i<sum;i++){
            kehu[i].show();
        }
    }
    public double zongshouru(){
        double sum1=0;
        for (int i=0;i<sum;i++){
            sum1+=kehu[i].getMoney();
        }
        return sum1;
    }

}
